﻿package net.wangit.view.tree;

import net.wangit.jdbc.DB;
import net.wangit.jdbc.JDBCException;
import net.wangit.jdbc.util.DBHelper;
import net.wangit.support.TreeFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class DefaultTreeFactory extends TreeFactory {

	private static final Log log = LogFactory
			.getLog(net.wangit.view.tree.DefaultTreeFactory.class);
	private static final String SQL = "select * from TREE where tid=? and v=1 order by o";

	public DefaultTreeFactory() {
	}

	public Tree createTree(String domain) {
		String treeId = getConfig().getTreeId();
		net.wangit.MapList list;
		try {
			DB db = DBHelper.getDomainDB(domain);
			list = db.query(DefaultTreeFactory.SQL, treeId, 2);
			return TreeUtil.getTree(list);
		} catch (JDBCException e) {
			log.error((new StringBuilder("could not create tree by ")).append(
					domain).append("/").append(getConfig().getTreeId())
					.toString(), e);
			return null;
		}
	}

}
